package cn.udrm.water.base.v1.manager.repository;

import java.util.List;

import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.EntityGraph.EntityGraphType;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import cn.udrm.water.base.v1.manager.entities.BaseRole;

@Repository
public interface BaseRoleRepository extends JpaRepository<BaseRole, String> {

	public List<BaseRole> findByOrganizationId(String organizationId);
	
	
	@Query(value="FROM BaseRole WHERE id=?1")
	public BaseRole get(String id);
	
	@Query(value="FROM BaseRole WHERE id=?1")
	@EntityGraph(value="BaseRole.departments", type=EntityGraphType.FETCH)
	public BaseRole findWithDepartmentsById(String id);
	
	@Query(value="FROM BaseRole WHERE id=?1")
	@EntityGraph(value="BaseRole.persons", type=EntityGraphType.FETCH)
	public BaseRole findWithPersonsById(String id);
	
	@Query(value="FROM BaseRole WHERE id=?1")
	@EntityGraph(value="BaseRole.resources", type=EntityGraphType.FETCH)
	public BaseRole findWithResourcesById(String id);
	
	@Query(value="FROM BaseRole WHERE id=?1")
	@EntityGraph(value="BaseRole.organization", type=EntityGraphType.FETCH)
	public BaseRole findParentOrganizationById(String id);
}
